package com.ruoyi.project.system.notification.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.system.notification.domain.PlatformNotification;
import com.ruoyi.project.system.notification.mapper.PlatformNotificationMapper;
import com.ruoyi.project.system.notification.service.IPlatformNotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * 平台通知Service业务层处理
 *
 * @author LCL
 * @date 2021-10-08
 */
@Service
public class PlatformNotificationServiceImpl implements IPlatformNotificationService
{
    @Autowired
    private PlatformNotificationMapper platformNotificationMapper;

    /**
     * 查询平台通知
     *
     * @param id 平台通知ID
     * @return 平台通知
     */
    @Override
    public PlatformNotification selectPlatformNotificationById(String id)
    {
        return platformNotificationMapper.selectPlatformNotificationById(id);
    }

    /**
     * 查询平台通知列表
     *
     * @param platformNotification 平台通知
     * @return 平台通知
     */
    @Override
    public List<PlatformNotification> selectPlatformNotificationList(PlatformNotification platformNotification)
    {
        return platformNotificationMapper.selectPlatformNotificationList(platformNotification);
    }

    /**
     * 新增平台通知
     *
     * @param platformNotification 平台通知
     * @return 结果
     */
    @Override
    public int insertPlatformNotification(PlatformNotification platformNotification)
    {
        platformNotification.setId(UUID.randomUUID().toString().replace("-",""));
        platformNotification.setCreated(new Date());
        return platformNotificationMapper.insertPlatformNotification(platformNotification);
    }

    /**
     * 修改平台通知
     *
     * @param platformNotification 平台通知
     * @return 结果
     */
    @Override
    public int updatePlatformNotification(PlatformNotification platformNotification)
    {
        return platformNotificationMapper.updatePlatformNotification(platformNotification);
    }

    /**
     * 删除平台通知对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePlatformNotificationByIds(String ids)
    {
        return platformNotificationMapper.deletePlatformNotificationByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除平台通知信息
     *
     * @param id 平台通知ID
     * @return 结果
     */
    @Override
    public int deletePlatformNotificationById(String id)
    {
        return platformNotificationMapper.deletePlatformNotificationById(id);
    }

    @Override
    public PageInfo<PlatformNotification> getPlatformNotification(Integer pageNum, Integer pageSize, String memberId) {
        PageHelper.startPage(pageNum,pageSize);
        PlatformNotification notification = new PlatformNotification();
        notification.setStatus(0);
        notification.setType(0);
        List<PlatformNotification> list = platformNotificationMapper.selectPlatformNotificationList(notification);
        PageInfo<PlatformNotification> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
